package org.example.maven.utils;


import com.google.code.kaptcha.text.impl.DefaultTextCreator;

import java.util.Random;

public class KaptchaTextCreator extends DefaultTextCreator {
    private static final String[] CNUMBERS = "0,1,2,3,4,5,6,7,8,9,10".split(",");
    @Override
    public String getText() {
        Random random=new Random();
        int result=0;
        int temp1=random.nextInt(10);
        int temp2=random.nextInt(10);
        StringBuilder suChinese = new StringBuilder();
        int select=random.nextInt(3);
        if(select==0){
            result=temp1*temp2;
            suChinese.append(CNUMBERS[temp1]);
            suChinese.append("*");
            suChinese.append(CNUMBERS[temp2]);
        }
        else if(select == 1){
            if(temp2!=0&&temp1 % temp2 == 0){
                result=temp1/temp2;
                suChinese.append(CNUMBERS[temp1]);
                suChinese.append("/");
                suChinese.append(temp2);
            }
            else {
                result=temp1+temp2;
                suChinese.append(temp1);
                suChinese.append("+");
                suChinese.append(temp2);
            }
        }
        else {
            if(temp1>=temp2){
                result=temp1-temp2;
                suChinese.append(temp1);
                suChinese.append("-");
                suChinese.append(temp2);
            }
            else {
                result=temp2-temp1;
                suChinese.append(temp2);
                suChinese.append("-");
                suChinese.append(temp1);
            }
        }
        suChinese.append("=?@" + result);
        return suChinese.toString();
    }
}
